package com.sphd.beautysalon.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sphd.beautysalon.info.SortInfo;
import com.sphd.beautysalon.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Hu on 2016/11/22.
 */

public class TypeFoodAdapter extends BaseAdapter {
    int item_type_food_order;
    List<SortInfo> sortInfos;
    private int selectItem = -1;

    public int getSelectItem() {
        return selectItem;
    }

    public void setSelectItem(int selectItem) {
        this.selectItem = selectItem;
    }

    public TypeFoodAdapter(int item_type_food_order, List<SortInfo> sortInfos) {
        this.item_type_food_order = item_type_food_order;
        this.sortInfos = sortInfos;
    }

    @Override
    public int getCount() {
        return sortInfos.size();
    }

    @Override
    public Object getItem(int i) {
        return sortInfos.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        SortInfo sortInfo = sortInfos.get(i);
        ViewHolder viewHolder = null;
        if (view == null) {
            view = View.inflate(viewGroup.getContext(), R.layout.item_type_food_order, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.foodName.setText(sortInfo.getSort());
            viewHolder.titleCheckFlag.setVisibility(sortInfo.isSelectItem() ? View.VISIBLE : View.INVISIBLE);
        if (selectItem == i) {
            viewHolder.titleCheckFlag.setVisibility(View.VISIBLE );
        } else {
            viewHolder.titleCheckFlag.setVisibility(View.INVISIBLE );
        }
        viewHolder.foodNum.setText(sortInfo.getAllNo()==0?"":sortInfo.getAllNo() + "");

        return view;
    }

    static class ViewHolder {
        @BindView(R.id.title_check_flag)
        TextView titleCheckFlag;
        @BindView(R.id.food_name)
        TextView foodName;
        @BindView(R.id.food_num)
        TextView foodNum;
        @BindView(R.id.relative_onclick)
        RelativeLayout relativeOnclick;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
